/*******************************************************************************
* This file provides the functions to retrieve the following GPS information
* from the NMEA 0183 sentences:
* ~ Latitude and Longitude.
* ~ Altitude.
* ~ Speed over ground.
* ~ Course over ground.
* ~ HDOP.
* ~ Number of Satelites Fixed.
*
* This API is tested to be working with the LS20031 GPS module. For other
* GPS module, minor modification may be needed.
*
* Author: Kong Wai Weng
* Email:  waiweng83@gmail.com
*******************************************************************************/



#ifndef _HAL_GPS_H
#define _HAL_GPS_H



#include <string.h>
#include "system.h"
#include "variables.h"
#include "task.h"



/*******************************************************************************
* STRUCTURE AND UNION DEFINITION                                               *
*******************************************************************************/

// Data for date and time.
struct RTC_DATA {
	unsigned int uiMillisecond;		// Milliseconds.
	unsigned char ucSecond;			// Seconds.
	unsigned char ucMinute;			// Minutes.
	unsigned char ucHour;			// Hours.
	unsigned char ucDate;			// Date.
	unsigned char ucMonth;			// Month.
	unsigned char ucYear;			// Year (20xx).
};	



// Data from the GPS.
struct GPS_DATA {
	// GPS fix status.
	// 0 = Not fixed, 1 = Fixed.
    unsigned char ucFixStatus;
    
    // The current date and time.
    struct RTC_DATA xDateTime;
    
	// The current coordinate.
	// Unit = degree.
	float fLatitude;
	float fLongitude;
	
	// The current ground speed.
	// Unit = m/s.
	float fGroundSpeed;
	
	// The current ground course (0 - 359.99).
	// Unit = degree.
	float fGroundCourse;
	
	// The current altitude.
	// Unit = m.
	float fAltitude;
	
	// Number of satelites used (0 - 12).
	unsigned int uiNumberOfSatelites;
	
	// HDOP * 10.
	float fHdop;
};



/*******************************************************************************
* PUBLIC FUNCTION PROTOTYPES                                                   *
*******************************************************************************/

/*******************************************************************************
* PUBLIC FUNCTION: xGetGpsData
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ The GPS data.
*
* DESCRIPTIONS:
* Get the GPS data.
*
*******************************************************************************/
struct GPS_DATA xGetGpsData(void);



/*******************************************************************************
* PUBLIC FUNCTION: vParseGpsData
*
* PARAMETERS:
* ~ uiReceivedData		- The current character received from the UART.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Parse the GPS data to extract the relavant information.
*
*******************************************************************************/
void vParseGpsData(unsigned int uiReceivedData);



/*******************************************************************************
* TASK: taskGPSWatchdog
*
* DESCRIPTIONS:
* This task monitors the GPS heartbeat. If no GPS data is received
* after the timeout period, the error flag will be set.
*
*******************************************************************************/
portTASK_FUNCTION_PROTO(taskGPSWatchdog, pvParameters);



#endif
